﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using ToolsLayer;
using System.Data;

namespace Webcar.Sec
{
    public partial class SecWinterReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.SelectByDate1.SetDeptDisable();
            this.SelectByDate1.SearchClick += new Webcar.Controls.SelectByDate.OnSearchClickDelegate(SelectByMonth1_SearchClick);
            if (this.IsPostBack) return;
        }
        void SelectByMonth1_SearchClick(object sender, EventArgs e)
        {
            string start = this.SelectByDate1.GetStartDate();
            string end = this.SelectByDate1.GetEndDate();
            string sql = @"select sum(a.czld) czld,sum(a.cdjcry) cdjcry,sum(a.jccl) jccl,sum(a.jcry) jcry,sum(a.clyh) clyh,
                            sum(a.ryyh) ryyh,sum(a.glyh) glyh,sum(a.fhl) fhl,sum(a.sjm) sjm
                            ,sum(a.tq) tq,sum(a.qt) qt,sum(a.aqjy) aqjy,sum(a.jnpx) jnpx,sum(a.gcsy) gcsy,sum(a.gcly) gcly,sum(a.scbcl) scbcl
                            ,b.dept_name from sec_report_winter a,dept b 
                            where a.dept_code=b.dept_code and a.dept_code in (select dept_code from bs_man_dept where man_code='{0}') and isnull(b.del_flag,'F')='F'
                            and a.check_day between '{1}' and '{2}'
                            group by b.dept_name";
            sql = string.Format(sql, CurrentUser.LoginUserID,start,end);

            this.GridView1.DataSource = DB.ExecuteDataset(sql);
            this.GridView1.DataBind();

        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                DataSet data = this.GridView1.DataSource as DataSet;
                DataTable table = data.Tables[0];
                e.Row.Cells[0].Text = "合计：";
                e.Row.Cells[1].Text = table.Compute("sum(czld)", "").ToString();
                e.Row.Cells[2].Text = table.Compute("sum(cdjcry)", "").ToString();
                e.Row.Cells[3].Text = table.Compute("sum(jccl)", "").ToString();
                e.Row.Cells[4].Text = table.Compute("sum(jcry)", "").ToString();
                e.Row.Cells[5].Text = table.Compute("sum(clyh)", "").ToString();
                e.Row.Cells[6].Text = table.Compute("sum(ryyh)", "").ToString();
                e.Row.Cells[7].Text = table.Compute("sum(glyh)", "").ToString();
                e.Row.Cells[8].Text = table.Compute("sum(fhl)", "").ToString();
                e.Row.Cells[9].Text = table.Compute("sum(gcsy)", "").ToString();
                e.Row.Cells[10].Text = table.Compute("sum(gcly)", "").ToString();
                e.Row.Cells[11].Text = table.Compute("sum(scbcl)", "").ToString();

                e.Row.Cells[12].Text = table.Compute("sum(sjm)", "").ToString();
                e.Row.Cells[13].Text = table.Compute("sum(tq)", "").ToString();
                e.Row.Cells[14].Text = table.Compute("sum(qt)", "").ToString();
                e.Row.Cells[15].Text = table.Compute("sum(aqjy)", "").ToString();
                e.Row.Cells[16].Text = table.Compute("sum(jnpx)", "").ToString();

                e.Row.Font.Bold = true;

            }
        }
    }
}
